home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 201-225 / disk_218 / edlib / strtok.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  906b  |  30 lines

  1. /*
  2.  * edlib v1.1 Copyright 1989 Edwin Hoogerbeets
  3.  * This code is freely redistributable as long as no charge other than
  4.  * reasonable copying fees are levied for it.
  5.  */
  6.  
  7. #define STRING_END      '\0'
  8. #ifndef NULL
  9. #define NULL    0L
  10. #endif
  11.  
  12. char *strtok(buf, separators)
  13. register char *buf, *separators;
  14. {
  15.         register char *token, *end;     /* Start and end of token. */
  16.         extern char *strpbrk();
  17.         static char *fromLastTime;
  18.  
  19.         if (token = buf ? buf : fromLastTime) {
  20.                 token += strspn(token, separators);     /* Find token! */
  21.                 if (*token == STRING_END)
  22.                         return(NULL);
  23.                 fromLastTime = ((end = strpbrk(token,separators))
  24.                                 ? &end[1]
  25.                                 : NULL);
  26.                 *end = STRING_END;                      /* Cut it short! */
  27.         }
  28.         return(token);
  29. }
  30.